﻿using System;
using System.Dynamic;

namespace RuntimeHelloWorlds
{
	/// <summary>
	/// Hopefully, a self-explanatory implementation of DynamicObject
	/// </summary>
	public class DynamicObjectHelloWorld
	{
		public void SayHelloWorld()
		{
			dynamic hwDynamic = new HwInvokeDynamic();
			hwDynamic.HelloWorld();
		}
	}

	public class HwInvokeDynamic : DynamicObject
	{
		public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
		{
			if (string.Compare(binder.Name, "HelloWorld", true) == 0)
			{
				Console.WriteLine("Hello, World! (Dynamic Object)");
				result = null;
				return true;
			}
			else
			{
				throw new NotImplementedException();
			}
		}
	}
}
